<?php //pack11class

class Property {

    public $id;
    public $parent;
    public $system;
    public $type;
    public $group;
    public $groupNum;
    public $field;
    
    public $hasValue;
    public $isValue;
    public $combined;
    public $sortable;
    public $search;
    public $setting;
    
    public $value;
    public $value2;
    
    public $level0=false;
    public $level1=false;

    public $label="Property";
    public $string;

    public $city24=NULL;

    public $traceEnabled=true;

    public function availableValues($echo=false) {
        $whereString=(PropertiesManager::definedSQLFor($this))? " AND ".PropertiesManager::definedSQLFor($this):"";
        if($this->system=="category") $whereString="";
        if($this->isValue){
            $sql=MySQLGet::process("Select `objects`.`{$this->field}` as `id`, `objects`.`{$this->field}` as `value` from ".MySQL::TABLE_OBJECTS." `objects` where `objects`.`{$this->field}` is not null{$whereString} group by `value` order by `value`;");
        } else if($this->hasValue){
            $sql=MySQLGet::process("Select `objects`.`value{$this->id}` as `order`, `objects`.`prop{$this->id}` as `id`, concat(`objects`.`value{$this->id}`,' ',`values`.`".LanguagesManager::field()."`) as `value` from ".MySQL::TABLE_OBJECTS." `objects` left join ".MySQL::TABLE_VALUES." `values` on (`values`.`id`=`objects`.`prop{$this->id}`) where `objects`.`value{$this->id}` is not null{$whereString} group by `value` order by `order`;");
        } else {
            $sql=MySQLGet::process("Select `objects`.`{$this->field}` as `id`, `values`.".LanguagesManager::sql()." from ".MySQL::TABLE_OBJECTS." `objects` left join ".MySQL::TABLE_VALUES." `values` on (`values`.`id`=`objects`.`{$this->field}`) where `objects`.`{$this->field}` is not null{$whereString} group by `value` order by `value`;");
        }
        $cc=MySQLGet::$cc;
        //trace(MySQLGet::getQuery());
        //if($echo) echo(MySQLGet::getQuery());
        //if($echo) echo "<!-- ".count($sql)." -->";
        $values=array();
        if(!$sql) {
            //if($echo) echo(MySQLGet::getQuery());
            return $values;
        }
        foreach($sql as $row) {
            $value=new PropertyValue;
            $value->id=$row["id"];
            $value->value=$row["value"];
            array_push($values,$value);
        }
        return $values;
    }
    
	public function __toString() {
		return (strlen($this->value)>0)? $this->system."(".$this->value.")":$this->system;
	}
	
}

?>